package fft;
import java.util.ArrayList;
import org.gwoptics.graphics.graph2D.Graph2D;
import org.gwoptics.graphics.graph2D.traces.Blank2DTrace;
import processing.core.PGraphics;
/**
 * @brief This takes in 2 sets of data representing a line and calculates plots
 * for them on the graph.
 * @author Frequency Flyers
 */
public class LineGraph extends Blank2DTrace
{
    double [] Xdata;
    double [] Ydata;
    float  [] color;
    int alpha = 1;
    ArrayList _data;
    
    /**Bind the data to a set of points*/
    public void bindData(double[] x, double[] y, float[] c)
    {
        Xdata = x;
        Ydata = y;
        color = c;
        _data = new ArrayList();
        for(int i = 0; i < Xdata.length; i++)
        {
            _data.add(new Point2D(Xdata[i], Ydata[i]));
        }
    }
    
    /**Calculate the points and draw the line*/
    public void drawPoint(Point2D p1, Point2D p2,PGraphics pg)
    {
        pg.pushStyle();
        pg.stroke(color[0],color[1],color[2],color[3]);
        update(pg);
        //System.out.println((float)p1.X +" " + (float)p1.Y + " " + (float)p2.X +" " + (float)p2.Y );
        pg.line((float)p1.X,(float)p1.Y,(float)p2.X,(float)p2.Y);
        pg.popStyle();
        
    }

    /**Draw the graph*/
    @Override
    public void TraceDraw(PGraphics pg) 
    {
        for(int i = 1; i < _data.size(); i++)
        {
            drawPoint((Point2D)_data.get(i-1), (Point2D)_data.get(i), pg);
        }        
    }
    
    /**Set weight of lines*/
    public void setWeight(int value)
    {
        //color[3] = value;
        alpha = value;
    }
    
    /**Update the graph colors*/
    public void update(PGraphics pg)
    {
        pg.strokeWeight(alpha);
        pg.flush();
    }
}
